﻿using System.Collections.Generic;
using System.Web.Mvc;
using System.Web.Routing;
using Xoohoo.Extensions;

namespace Xoohoo.Html
{
    public static class LinkExtensions
    {
        #region Link

        public static MvcHtmlString Link(this HtmlHelper htmlHelper, string linkText, string href)
        {
            return htmlHelper.Link(linkText, href, null,null);
        }
        public static MvcHtmlString Link(this HtmlHelper htmlHelper, string linkText, string href,string title)
        {
            return htmlHelper.Link(linkText, href, title, null);
        }
        public static MvcHtmlString Link(this HtmlHelper htmlHelper, string linkText, string href, object htmlAttributes)
        {
            return htmlHelper.Link(linkText, href,null, new RouteValueDictionary(htmlAttributes));
        }
        public static MvcHtmlString Link(this HtmlHelper htmlHelper, string linkText, string href, string title, object htmlAttributes)
        {
            return htmlHelper.Link(linkText, href,title, new RouteValueDictionary(htmlAttributes));
        }
        public static MvcHtmlString Link(this HtmlHelper htmlHelper, string linkText, string href, string title, IDictionary<string, object> htmlAttributes)
        {
            TagBuilder tagBuilder = new TagBuilder("a")
            {
                InnerHtml = linkText
            };
            tagBuilder.MergeAttributes(htmlAttributes);
            tagBuilder.MergeAttribute("href", href);
            if (!title.IsNullOrEmpty())
                tagBuilder.MergeAttribute("title", title);

            return MvcHtmlString.Create(tagBuilder.ToString(TagRenderMode.Normal));
        }

        #endregion
    }
}
